package com.oa.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.oa.entity.User;
import com.oa.service.TrendService;
import com.oa.util.AppUtil;
import com.oa.util.PageBean;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@Scope("prototype")
public class TrendAction<T> extends ActionSupport implements ModelDriven<T> {
  @Resource(name = "trendService")
	private static final long serialVersionUID = 1L;
	private TrendService service;// 通过Spring创建业务层对象 使用set方法依赖注入
	private PageBean<T> pageBean; // 封装了分页信息和数据内容的pageBean
	private List<T> listUser;// 用于储存pageBean当中被封装的User信息
	private int page = 1; // 表示从网页中返回的当前页的值 默认为1 表示默认显示第一页内容
	private User user = new User();

	@SuppressWarnings("unchecked")
	public String selectLink() {
    
		this.service = AppUtil.getBean("trendService", TrendService.class);
		this.pageBean = (PageBean<T>) service.queryForPage(5, page, user);// 获取封装了分页信息和数据的pageBean
		this.listUser = this.pageBean.getList(); // 获取数据

		ActionContext.getContext().put("user", user);
		  System.out.println("====="+pageBean+"====");
		  System.out.println(user+"=========");
		return "link";
	}

	public String execute() throws Exception {
		return "NONE";
	}

	public T getModel() {
		return null;
	}

	public TrendService getService() {
		return service;
	}

	public void setService(TrendService service) {
		this.service = service;
	}

	public PageBean<T> getPageBean() {
		return pageBean;
	}

	public void setPageBean(PageBean<T> pageBean) {
		this.pageBean = pageBean;
	}

	public List<T> getListUser() {
		return listUser;
	}

	public void setListUser(List<T> listUser) {
		this.listUser = listUser;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

}
